package cn.wolfcode.trip.base.domain;

import com.alibaba.fastjson.JSON;
import lombok.Getter;
import lombok.Setter;

import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Getter
@Setter
public class Product extends BaseDomain{
    //商品名
    private String name;
    //商品图片
    private String imgUrl;
    //商品售价
    private int price;
    //商品库存
    private Integer count;
    //商品简介
    private String intro;
    //商品上架状态
    private Integer putAwayState=-1;
    //商品上新时间
    private Date creatTime;
    //商品详情
    private ProductContent productContent;

    public String getPutAwayStateName(){
        String name;
            if(0==putAwayState){
                return name="下架状态";
            }else if(1==putAwayState){
                return name="上架状态";
            }else {
                return name="查无此商品";
            }
    }

    public String getJson() {
        //共享给按钮的json数据
        Map<String, Object> map = new HashMap<>();
        map.put("id", id);
        map.put("name", name);
        map.put("imgUrl", imgUrl);
        map.put("price", price);
        map.put("intro", intro);
        map.put("count", count);
        map.put("creatTime", creatTime);
        map.put("putAwayState", putAwayState);
        if (productContent != null){
            map.put("productContentId", productContent.id);
            map.put("productContentText", productContent.getContent());
        }
        return JSON.toJSONString(map);
    }

}